define([], function() {
	return {
		get: function(url, fn) {
			//建立ajax对象
			var xhr;
			if (window.XMLHttpRequest) {
				xhr = new XMLHttpRequest();
			} else {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			//建立连接
			xhr.open("GET", url, true);
			//发送请求
			xhr.send();
			//接收响应
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					if (fn) {
						fn(xhr.responseText); //回调函数
					}
				}
			}
		},

		post: function(url, arg, fn) {
			//建立ajax对象
			var xhr;
			if (window.XMLHttpRequest) {
				xhr = new XMLHttpRequest();
			} else {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			//建立连接
			xhr.open("POST", url, true);
			//发送请求
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xhr.send(arg);
			//接收响应
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					if (fn) {
						fn(xhr.responseText); //回调函数
					}
				}
			}
		},
		query:function (attr){
			var arr = location.href.split("?");
			if( arr.length>1 ){
				var col = arr[1].split("&");
				for(var i=0; i<col.length; i++){
					var a = col[i].split("=");
					if( a[0] == attr ){
						return a[1];
					}
				}
			}
			return "";
		},
		
		// 根据商品ID，求商品其他的属性
		getObject:function (id,obj){
			var arr = obj.listShow;
			var l = arr.length;
			var i = 0;
			for(; i<l; i++){
				var objQ = arr[i];
				if( objQ.pic_id == id ){
					return objQ;
				}
			}	
		}
	}
});
